import { Component, OnInit } from "@angular/core";
import { JsonApiService } from "app/core/api/json-api.service"; //http请求配置引入
import { Router } from "@angular/router"; //路由引入

declare var $: any;
@Component({
  selector: "examine-scheme",
  templateUrl: "./examine-scheme.component.html",
  styleUrls: ["./examine-scheme.css"],
})
export class ExamineSchemeComponent implements OnInit {
  tableData: any = []; //table数据
  totalCount: number = 0; //分页总条数
  curPage: number = 1; //分页当前页
  pageSize: number = 10; //内置的分页每页条数
  constructor(private jsonApiService: JsonApiService, private router: Router) {}
  ngOnInit() {
    this.load();
  }
  //table刷新
  refresh() {
    this.load();
  }
  //初始化加载list数据  TODO
  load() {
    let data = {
      pageSize: this.pageSize,
      nowPage: this.curPage,
    };
    this.jsonApiService.json_http("examine/examineList.html", data)
      .subscribe((result) => {
        this.tableData = result.exhibitDatas || [];
        this.totalCount = result.recordCount;
      });
  }
  //分页回调
  paginate(e) {
    this.curPage = e.page + 1;
    this.pageSize = e.rows;
    this.load();
  }
  // 添加
  addExamineScheme() {
    this.router.navigate(['/device-management/examine-scheme/scheme-add'], {queryParams: {type:'new'}});
  }
  // 删除
  examineDelete(row) {
    console.log(row)
    let data = [row.id]
    this.jsonApiService.confirm_message("此操作将永久删除数据,确认要删除?").then(()=>{
			this.jsonApiService.json_http("examine/delExamine.html", data)
      .subscribe((result) => {
        this.load();
        this.jsonApiService.message(result.message);
      });
		})
  }
  // 编辑
  examineEdit(row, type) {
    if(type == 'edit') {
      this.router.navigate(['/device-management/examine-scheme/scheme-add'], {queryParams: {type:'edit', id: row.id}});
    }else {
      console.log('see')
      this.router.navigate(['/device-management/examine-scheme/scheme-add'], {queryParams: {type:'see', id: row.id}});
    }
  }
}
